// 排片--持久层
var mongoose = require('mongoose');
const getSeatByTheaterId=async _id=>await mongoose.model('seats').find(_id)


const getSeating=async _id=>await mongoose.model('seating')
.find(_id)
.populate(
  { path: 'scheduleId'}
)
.populate(
  { path: 'seatId'}
)
.exec()


const addSeating=async data=>await mongoose.model('seating').insertMany(data)
const getById=async (data) =>await mongoose.model('schedules')
.find(data)
.populate(
  { path: 'cinemasId'}
)
.populate(
  { path: 'theaterId'}
)
.populate(
  { path: 'movieId'}
)
.exec()
//新增排片数据关联
const addData=async(data)=>{
    return await mongoose.model('schedules').create(data)
  }
  //删除拍片数据
const deleteSchedules=async(_id)=>{
    return await mongoose.model('schedules').deleteOne(_id)
  }


const updata=async (_id,data)=> await mongoose.model('schedules').updateOne({_id:_id},data)



const getMovies=async ()=> await mongoose.model('movies').find()


const isHave=async (data)=> await mongoose.model('schedules').find(data)



//查找关联数据具体内容
const getSchedules=async ()=> await mongoose.model('schedules').find()
.populate({
  path: 'movieId'})
.populate(
  { path: 'cinemasId'}
)
.populate(
  { path: 'theaterId'}
)
.exec()
const getCinems=async ()=> await mongoose.model('cinemas').find()
const getTheaters=async (_id)=> {
  return  await mongoose.model('theaters')
  .find({cinemasId:_id}) //对应结果查询
}
module.exports = {addData,getMovies,getCinems,getTheaters,getSchedules,deleteSchedules,isHave,updata,getById,getSeatByTheaterId,addSeating,getSeating}